﻿@using Blazor.Localization
@inherits Blazor.Core.SoraniFeedbackComponentBase<string, Uri?>
@inject IStringLocalizer<UpdateSettingLocalization> Loc

<Form @ref="_form" Model="_model" LabelColSpan="8" WrapperColSpan="16" LabelAlign="AntLabelAlignType.Left">
    <FormItem Label="@Loc[UpdateSettingLocalization.LatestNativeVersion]">
        <Input @bind-value="@context.ResourceUrl"/>
    </FormItem>
</Form>

@code
{
    private class FormData
    {
        public string ResourceUrl { get; set; }
    }

    private FormData _model;
    private Form<FormData> _form;

    protected override void OnInitialized()
    {
        _model = new FormData()
        {
            ResourceUrl = Options
        };

        base.OnInitialized();
    }

    public override Task OnFeedbackOkAsync(ModalClosingEventArgs args)
    {
        if (!_form.Validate())
        {
            args.Reject();
            return Task.CompletedTask;
        }

        var uri = new Uri(_model.ResourceUrl);
        OkCancelRefWithResult.OkAsync(uri);

        return Task.CompletedTask;
    }
}